<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\Reward;
use Illuminate\Support\Facades\Cache;

class RewardsController extends Controller
{
	public function records()
	{
		$user = request()->user();
		$condition = request('condition');

		if(!$condition){
			$query = Reward::query();
		}else{

			$query = Reward::query()->where('remark',$condition);
		}
		

		$query = $query->where('user_id', $user->id);
		$query = !empty(request('start_time')) ? $query->where('created_at', '>', request('start_time')) : $query;
		$query = !empty(request('end_time')) ? $query->where('created_at', '<', request('end_time')) : $query;
	
		$total = $query->sum('money');
		$cards = $query->orderByDesc('id')->paginate();

		
		return ['total' => $total, 'data' => $cards];
	}
}
